package com.zeei.ems.base.util;

import com.github.pagehelper.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.util.*;

public class DateUtils {
    private static final Logger LOGGER = LoggerFactory.getLogger(DateUtils.class);
    private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    private static DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private static DateFormat dateTimeStrFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    private static DateFormat zhcnDateTimeStrFormat = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
    private static String twoDecimalFormat = "##0.0";
    public static final String DATE_YEAE_FORMAT = "yyyy";
    public static final String DATE_MONTH_FORMAT = "yyyy-MM";
    public static final String DATE_FORMAT = "yyyy-MM-dd";
    public static final String DATE_HOUR_FORMAT = "yyyy-MM-dd HH";
    public static final String DATE_MIN_FORMAT = "yyyy-MM-dd HH:mm";
    public static final String TIMEF_FORMAT = "yyyy-MM-dd HH:mm:ss";
    public static final String FULL_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
    public static final String ZHCN_YEAR_FORMAT = "yyyy年";
    public static final String ZHCN_MONTH_FORMAT = "yyyy年MM月";
    public static final String ZHCN_DAY_FORMAT = "yyyy年MM月dd日";
    public static final String ZHCN_HOUR_FORMAT = "yyyy年MM月dd日HH时";
    public static final String ZHCN_MIN_FORMAT = "yyyy年MM月dd日HH时mm分";
    public static final String ZHCN_TIME_FORMAT = "yyyy年MM月dd日HH时mm分ss秒";
    public static final String TIME_STR_FORMAT = "yyyyMMddHHmmss";
    public static final String TIMESSS_STR_FORMAT = "yyyyMMddHHmmssSSS";
    public static final String DATE_STR_FORMAT = "yyyyMMdd";
    public static final String DATE_SIMPLE_SHORT_FORMAT = "yyMMdd";
    public static final int DATE_YEAR = 0;
    public static final int DATE_SEASON = 1;
    public static final int DATE_MONTH = 2;

    public DateUtils() {
    }

    public Date convert(String source) {
        if (StringUtils.isEmpty(source)) {
            return null;
        } else {
            List<String> formarts = new ArrayList();
            formarts.add("yyyy-MM-dd");
            formarts.add("yyyy-MM-dd HH:mm");
            formarts.add("yyyy-MM-dd HH:mm:ss");
            if (StringUtils.isEmpty(source)) {
                return null;
            } else {
                String date = source.trim();
                if (date.matches("^\\d{4}-\\d{1,2}-\\d{1,2}$")) {
                    return parseDate(date, (String)formarts.get(0));
                } else if (date.matches("^\\d{4}-\\d{1,2}-\\d{1,2} {1}\\d{1,2}:\\d{1,2}$")) {
                    return parseDate(date, (String)formarts.get(1));
                } else {
                    return date.matches("^\\d{4}-\\d{1,2}-\\d{1,2} {1}\\d{1,2}:\\d{1,2}:\\d{1,2}$") ? parseDate(date, (String)formarts.get(2)) : null;
                }
            }
        }
    }

    public static String getTimebyMinAfter(int nMinute) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.add(12, nMinute);
        return dateTimeFormat.format(now.getTime());
    }

    public static String getTimebySecAfter(int n) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.add(13, n);
        return dateTimeFormat.format(now.getTime());
    }

    private static DateFormat getDateFormat(String formatStr) {
        if (formatStr.equalsIgnoreCase("yyyy-MM-dd")) {
            return dateFormat;
        } else {
            return (DateFormat)(formatStr.equalsIgnoreCase("yyyy-MM-dd HH:mm:ss") ? dateTimeFormat : new SimpleDateFormat(formatStr));
        }
    }

    public static String dateToDateString(Date date) {
        return dateToDateString(date, "yyyy-MM-dd HH:mm:ss");
    }

    public static String dateToDateString(Date date, String formatStr) {
        DateFormat df = getDateFormat(formatStr);
        return df.format(date);
    }

    public static String dateToDateString(String date, String formatStr) {
        DateFormat df = getDateFormat(formatStr);
        return df.format(date);
    }

    public static String getDateString(Date date) {
        DateFormat df = getDateFormat("yyyy-MM-dd");
        return df.format(date);
    }

    public static long getMicroSec(BigDecimal hours) {
        BigDecimal bd = hours.multiply(new BigDecimal(3600000));
        return bd.longValue();
    }

    public static String getToday(String pattern) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        DateFormat sdf = getDateFormat(pattern);
        sdf.setTimeZone(TimeZone.getDefault());
        return sdf.format(now.getTime());
    }

    public static int getCurrentMinutes() {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        return now.get(11) * 60 + now.get(12);
    }

    public static int getCurrentMin() {
        Calendar calendar = Calendar.getInstance();
        return calendar.get(12);
    }

    public static String getCurZhCNDateTime() {
        return dateToDateString(new Date(), "yyyy年MM月dd日HH时mm分ss秒");
    }

    public static Date getCurrentDate() {
        return new Date(System.currentTimeMillis());
    }

    public static String getCurrentDate(String format) {
        String strFormat = "yyyyMMddHHmmss";
        if (!StringUtil.isEmpty(format)) {
            strFormat = format;
        }

        SimpleDateFormat df = new SimpleDateFormat(strFormat);
        return df.format(new Date());
    }

    public static String getMonth() {
        Calendar now = Calendar.getInstance();
        int month = now.get(2) + 1;
        String monStr = String.valueOf(month);
        if (month < 10) {
            monStr = "0" + monStr;
        }

        return monStr;
    }

    public static String getDay() {
        Calendar now = Calendar.getInstance();
        int day = now.get(5);
        String dayStr = String.valueOf(day);
        if (day < 10) {
            dayStr = "0" + dayStr;
        }

        return dayStr;
    }

    public static String getMonth(Date date) {
        Calendar now = Calendar.getInstance();
        now.setTime(date);
        int month = now.get(2) + 1;
        String monStr = String.valueOf(month);
        if (month < 10) {
            monStr = "0" + monStr;
        }

        return monStr;
    }

    public static String getDay(Date date) {
        Calendar now = Calendar.getInstance();
        now.setTime(date);
        int day = now.get(5);
        String dayStr = String.valueOf(day);
        if (day < 10) {
            dayStr = "0" + dayStr;
        }

        return dayStr;
    }

    public static boolean isTimeExpired(String expireTime) {
        boolean ret = false;

        try {
            Date date = (new SimpleDateFormat("yyyyMMddHHmmss")).parse(expireTime);
            Calendar expire = Calendar.getInstance();
            expire.setTime(date);
            Calendar now = Calendar.getInstance();
            now.set(14, 0);
            if (now.after(expire)) {
                ret = true;
            }
        } catch (Exception var5) {
            LOGGER.error(String.format("DateUtil.isTimeExpired:%s", var5));
        }

        return ret;
    }

    public static String getExpireTimeByCalculate(Date startTime, int availableTime) {
        Calendar expire = Calendar.getInstance();
        expire.setTime(startTime);
        expire.add(13, availableTime);
        return (new SimpleDateFormat("yyyyMMddHHmmss")).format(expire.getTime());
    }

    public static String convertDateToString(Date date) {
        return (new SimpleDateFormat("yyyyMMddHHmmss")).format(date);
    }

    public static String convertDateToString(Date date, String format) {
        return (new SimpleDateFormat(format)).format(date);
    }

    public static Date convertStringToDate(String date) {
        try {
            return (new SimpleDateFormat("yyyyMMddHHmmss")).parse(date);
        } catch (Exception var2) {
            LOGGER.error(String.format("DateUtil.convertStringToDate:%s", var2));
            return new Date();
        }
    }

    public static Date convertStringToDate(String date, String formatString) {
        try {
            return !StringUtils.isEmpty(date) && !StringUtils.isEmpty(formatString) ? (new SimpleDateFormat(formatString)).parse(date) : null;
        } catch (Exception var3) {
            LOGGER.error(String.format("DateUtil.convertStringToDate:%s", var3));
            return new Date();
        }
    }

    public static Date convertDateToDate(Date date, String formatString) {
        try {
            return (new SimpleDateFormat(formatString)).parse(convertDateToString(date, formatString));
        } catch (Exception var3) {
            LOGGER.error(String.format("DateUtil.convertDateToDate:%s", var3));
            return new Date();
        }
    }

    public static String convertStringToString(String date, String formatString) {
        try {
            DateFormat df = new SimpleDateFormat(formatString);
            Date dateValue = convertStringToDate(date, "yyyy-MM-dd HH:mm:ss");
            return df.format(dateValue);
        } catch (Exception var4) {
            LOGGER.error(String.format("DateUtil.convertStringToString:%s", var4));
            return "";
        }
    }

    public static Date convertSimpleStringToDate(String date) throws ParseException {
        return (new SimpleDateFormat("yyyy-MM-dd")).parse(date);
    }

    public static String convertStringToZhCN(String date) throws ParseException {
        return zhcnDateTimeStrFormat.format(dateTimeStrFormat.parse(date));
    }

    public static Date convertSimpleStringToDateTime(String date) throws ParseException {
        return (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).parse(date);
    }

    public static Date getTodayDate() {
        Calendar cal = Calendar.getInstance();
        return cal.getTime();
    }

    public static String getYesterdayDateStr() {
        Calendar cal = Calendar.getInstance();
        cal.add(5, -1);
        Date yesterday = cal.getTime();
        return (new SimpleDateFormat("yyyy-MM-dd")).format(yesterday);
    }

    public static Date getYesterdayDate() {
        Calendar cal = Calendar.getInstance();
        cal.add(5, -1);
        return cal.getTime();
    }

    public static String getTomorrowDateStr() {
        Calendar cal = Calendar.getInstance();
        cal.add(5, 1);
        Date tomorrow = cal.getTime();
        return (new SimpleDateFormat("yyyy-MM-dd")).format(tomorrow);
    }

    public static Date getTomorrowDate() {
        Calendar cal = Calendar.getInstance();
        cal.add(5, 1);
        return cal.getTime();
    }

    public static String getStrDate(Calendar calendar, int strDateType) {
        String year = String.valueOf(calendar.get(1));
        String month = calendar.get(2) + 1 < 10 ? "0" + (calendar.get(2) + 1) : String.valueOf(calendar.get(2) + 1);
        String day = calendar.get(5) < 10 ? "0" + calendar.get(5) : String.valueOf(calendar.get(5));
        String strDate;
        switch(strDateType) {
            case 1:
                strDate = String.format("%s年%s月%s日", year, month, day);
                break;
            case 2:
                strDate = String.format("%s月%s日", month, day);
                break;
            case 3:
                strDate = String.format("%s年", year);
                break;
            case 4:
            default:
                strDate = String.format("%s-%s-%s", year, month, day);
                break;
            case 5:
                strDate = String.format("%s-%s", month, day);
                break;
            case 6:
                strDate = year;
        }

        return strDate;
    }

    public static Date getOffsetMonthDate(Date protoDate, int monthOffset) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(protoDate);
        cal.add(2, -monthOffset);
        return cal.getTime();
    }

    public static Date getOffsetDayDate(Date protoDate, int dateOffset) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(protoDate);
        cal.set(5, cal.get(5) - dateOffset);
        return cal.getTime();
    }

    public static Date getOffsetHourDate(Date protoDate, int offsetHour) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(protoDate);
        cal.set(11, cal.get(11) - offsetHour);
        return cal.getTime();
    }

    public static Date getAssignDate(Date currentDate, int assignYear, int assignMonth, int assignDay) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(currentDate);
        if (assignYear > -1) {
            cal.set(1, assignYear);
        }

        if (assignMonth > -1) {
            cal.set(2, assignMonth);
        }

        if (assignDay > -1) {
            cal.set(5, assignDay);
        }

        return cal.getTime();
    }

    public static int getHourCountBetweenDate(Date startDate, Date endDate) {
        Calendar startCalendar = Calendar.getInstance();
        startCalendar.setTime(startDate);
        startCalendar.set(12, 0);
        startCalendar.set(13, 0);
        Calendar endCalendar = Calendar.getInstance();
        endCalendar.setTime(endDate);
        endCalendar.set(12, 0);
        endCalendar.set(13, 0);

        int i;
        for(i = 0; endCalendar.compareTo(startCalendar) >= 0; ++i) {
            startCalendar.set(11, startCalendar.get(11) + 1);
        }

        return i;
    }

    public static int getDayCountBetweenDate(Date startDate, Date endDate) {
        Calendar startCalendar = Calendar.getInstance();
        startCalendar.setTime(startDate);
        Calendar endCalendar = Calendar.getInstance();
        endCalendar.setTime(endDate);

        int i;
        for(i = 0; endCalendar.compareTo(startCalendar) >= 0; ++i) {
            startCalendar.set(5, startCalendar.get(5) + 1);
        }

        return i;
    }

    public static int getMonthCountBetweenDate(Date startDate, Date endDate) {
        Calendar startCalendar = Calendar.getInstance();
        startCalendar.setTime(startDate);
        Calendar endCalendar = Calendar.getInstance();
        endCalendar.setTime(endDate);

        int i;
        for(i = 0; endCalendar.compareTo(startCalendar) >= 0; ++i) {
            startCalendar.set(2, startCalendar.get(2) + 1);
        }

        return i;
    }

    public static int getYearlyCountBetweenDate(Date startDate, Date endDate) {
        Calendar startCalendar = Calendar.getInstance();
        startCalendar.setTime(startDate);
        Calendar endCalendar = Calendar.getInstance();
        endCalendar.setTime(endDate);

        int i;
        for(i = 0; endCalendar.compareTo(startCalendar) >= 0; ++i) {
            startCalendar.set(1, startCalendar.get(2));
        }

        return i;
    }

    public static Date getOffsetSimpleDate(Date protoDate, int dateOffset, int type) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(protoDate);
        cal.set(5, cal.get(5) - dateOffset);
        if (type == 1) {
            cal.set(11, 0);
            cal.set(12, 0);
        }

        if (type == 2) {
            cal.set(12, 0);
        }

        cal.set(13, 0);
        cal.set(14, 0);
        return cal.getTime();
    }

    public static String getDateToString() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        Date date = new Date();
        return dateFormat.format(date);
    }

    public static String getTodayTimeString() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        return dateFormat.format(date);
    }

    public static Date addSecond(Date dateTime, int nSecond) {
        Calendar cd = Calendar.getInstance();
        cd.setTime(dateTime);
        cd.add(13, nSecond);
        return cd.getTime();
    }

    public static String addSecond(Date m, int n, String formatstring) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(formatstring);
            Calendar cd = Calendar.getInstance();
            cd.setTime(m);
            cd.add(13, n);
            return sdf.format(cd.getTime());
        } catch (Exception var5) {
            LOGGER.error(String.format("DateUtil.addSecond formatstring:%s", var5));
            return "";
        }
    }

    public static String addSecond(String dateTime, int nSecond) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Calendar cd = Calendar.getInstance();
            cd.setTime(sdf.parse(dateTime));
            cd.add(13, nSecond);
            return sdf.format(cd.getTime());
        } catch (Exception var4) {
            LOGGER.error(String.format("DateUtil.addSecond:%s", var4));
            return "";
        }
    }

    public static Date addMinute(Date dateTime, int nMinute) {
        Calendar cd = Calendar.getInstance();
        cd.setTime(dateTime);
        cd.add(12, nMinute);
        return cd.getTime();
    }

    public static String addMinute(Date dateTime, int nMinute, String formatstring) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(formatstring);
            Calendar cd = Calendar.getInstance();
            cd.setTime(dateTime);
            cd.add(12, nMinute);
            return sdf.format(cd.getTime());
        } catch (Exception var5) {
            LOGGER.error(String.format("DateUtil.addMinute:%s", var5));
            return "";
        }
    }

    public static Date addHour(Date dateTime, int nHour) {
        Calendar cd = Calendar.getInstance();
        cd.setTime(dateTime);
        cd.add(11, nHour);
        return cd.getTime();
    }

    public static String addHour(Date dateTime, int nHour, String formatstring) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(formatstring);
            Calendar cd = Calendar.getInstance();
            cd.setTime(dateTime);
            cd.add(11, nHour);
            return sdf.format(cd.getTime());
        } catch (Exception var5) {
            LOGGER.error(String.format("DateUtil.addHour:%s", var5));
            return "";
        }
    }

    public static String addDay(String dateTime, int nDay) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar cd = Calendar.getInstance();
            cd.setTime(sdf.parse(dateTime));
            cd.add(5, nDay);
            return sdf.format(cd.getTime());
        } catch (Exception var4) {
            LOGGER.error(String.format("DateUtil.addDay:%s", var4));
            return "";
        }
    }

    public static Date addDay(Date dateTime, int nDay) {
        Calendar cd = Calendar.getInstance();
        cd.setTime(dateTime);
        cd.add(5, nDay);
        return cd.getTime();
    }

    public static Date addMonth(Date dateTime, int nMonth) {
        Calendar cd = Calendar.getInstance();
        cd.setTime(dateTime);
        cd.add(2, nMonth);
        return cd.getTime();
    }

    public static String addMonth(Date dateTime, int nMonth, String formatstring) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(formatstring);
            Calendar cd = Calendar.getInstance();
            cd.setTime(dateTime);
            cd.add(2, nMonth);
            return sdf.format(cd.getTime());
        } catch (Exception var5) {
            LOGGER.error(String.format("DateUtil.addMonth formatstring:%s", var5));
            return "";
        }
    }

    public static String addMonth(String dateTime, int nMonth, String format) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            Calendar cd = Calendar.getInstance();
            cd.setTime(sdf.parse(dateTime));
            cd.add(2, nMonth);
            return sdf.format(cd.getTime());
        } catch (Exception var5) {
            return null;
        }
    }

    public static String addMonth(String dateTime, int nMonth) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar cd = Calendar.getInstance();
            cd.setTime(sdf.parse(dateTime));
            cd.add(2, nMonth);
            return sdf.format(cd.getTime());
        } catch (Exception var4) {
            LOGGER.error(String.format("DateUtil.addMonth:%s", var4));
            return "";
        }
    }

    public static String addYear(Date dateTime, int nYear, String formatstring) {
        Calendar cd = Calendar.getInstance();
        cd.setTime(dateTime);
        cd.add(1, nYear);
        DateFormat sdf = new SimpleDateFormat(formatstring);
        return sdf.format(cd.getTime());
    }

    public static String[] getExecDay(Date lastDate) {
        String[] day = null;
        Date yesdate = null;

        try {
            yesdate = convertDateToDate(getYesterdayDate(), "yyyy-MM-dd");
        } catch (Exception var6) {
            LOGGER.error(String.format("DateUtil.getExecDay:%s", var6));
        }

        int dayCount = getDayCountBetweenDate(lastDate, yesdate);
        if (dayCount <= 0) {
            return day;
        } else if (dayCount == 1) {
            return new String[]{getYesterdayDateStr()};
        } else {
            day = new String[dayCount];

            for(int i = 0; i < dayCount; ++i) {
                String date = (new SimpleDateFormat("yyyy-MM-dd HH")).format(addDay(lastDate, i));
                day[i] = date;
            }

            return day;
        }
    }

    public static String[] getExecYearMonth(Date lastYearMonth) {
        String[] yearMonth = null;
        Date lastMonth = getOffsetMonthDate(new Date(), 1);

        try {
            lastMonth = convertDateToDate(lastMonth, "yyyy-MM");
        } catch (Exception var6) {
            LOGGER.error(String.format("DateUtil.getExecYearMonth:%s", var6));
        }

        int monthCount = getMonthCountBetweenDate(lastYearMonth, lastMonth);
        if (monthCount <= 0) {
            return yearMonth;
        } else if (monthCount == 1) {
            return new String[]{convertDateToString(lastMonth, "yyyy-MM")};
        } else {
            yearMonth = new String[monthCount];

            for(int i = 0; i < monthCount; ++i) {
                String date = addMonth(lastYearMonth, i, "yyyy-MM");
                yearMonth[i] = date;
            }

            return yearMonth;
        }
    }

    public static Date getFirstDayOfMonth() {
        Calendar ca = Calendar.getInstance();
        ca.set(5, 1);
        Date firstDate = ca.getTime();
        ca.add(2, 1);
        ca.add(5, -1);
        return firstDate;
    }

    public static Date getLastDayOfMonth() {
        Calendar ca = Calendar.getInstance();
        ca.set(5, 1);
        ca.add(2, 1);
        ca.add(5, -1);
        return ca.getTime();
    }

    public static String getBeginTime(int year, int month) {
        YearMonth yearMonth = YearMonth.of(year, month);
        LocalDate localDate = yearMonth.atDay(1);
        LocalDateTime startOfDay = localDate.atStartOfDay();
        ZonedDateTime zonedDateTime = startOfDay.atZone(ZoneId.of("Asia/Shanghai"));
        return convertDateToString(Date.from(zonedDateTime.toInstant()), "yyyy-MM-dd") + " 00:00:00";
    }

    public static String getEndTime(int year, int month) {
        YearMonth yearMonth = YearMonth.of(year, month);
        LocalDate endOfMonth = yearMonth.atEndOfMonth();
        LocalDateTime localDateTime = endOfMonth.atTime(23, 59, 59, 999);
        ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.of("Asia/Shanghai"));
        return convertDateToString(Date.from(zonedDateTime.toInstant()), "yyyy-MM-dd") + " 23:59:59";
    }

    public static int getDaysOfMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.getActualMaximum(5);
    }

    public static Date getLastTimeOfDay(Date dateTime) {
        Date date = dateTime;
        if (dateTime == null) {
            date = getCurrentDate();
        }

        Calendar ca = Calendar.getInstance();
        ca.setTime(date);
        ca.add(5, 1);
        ca.add(14, -1);
        date = ca.getTime();
        return date;
    }

    public static Date[] getDateSection(int dateType) {
        Date[] dateSection = new Date[2];
        if (DateUtils.DateConstants.TODAY.value == dateType) {
            dateSection[0] = getTodayDate();
            dateSection[1] = dateSection[0];
        } else if (DateUtils.DateConstants.NEARLYWEEK.value == dateType) {
            dateSection[0] = getOffsetDayDate(getTodayDate(), 6);
            dateSection[1] = getTodayDate();
        } else if (DateUtils.DateConstants.NEARLYMONTH.value == dateType) {
            dateSection[0] = getOffsetMonthDate(getTodayDate(), 1);
            dateSection[1] = getTodayDate();
        } else if (DateUtils.DateConstants.MONTH.value == dateType) {
            dateSection[0] = getFirstDayOfMonth();
            dateSection[1] = getLastDayOfMonth();
        } else if (DateUtils.DateConstants.LASTWEEK.value == dateType) {
            dateSection[0] = getOffsetDayDate(getTodayDate(), getWeekDay() + 6);
            dateSection[1] = getOffsetDayDate(getTodayDate(), getWeekDay());
        } else {
            dateSection = null;
        }

        return dateSection;
    }

    public static boolean isNumberic(String str) {
        if (StringUtil.isEmpty(str)) {
            return false;
        } else {
            int sz = str.length();

            for(int i = 0; i < sz; ++i) {
                if (!Character.isDigit(str.charAt(i))) {
                    return false;
                }
            }

            return true;
        }
    }

    public static String convertDateToOracleToDateExp(Date date, String format) {
        return "TO_DATE('" + (new SimpleDateFormat(format)).format(date) + "','YYYY-MM-DD HH24:MI:SS')";
    }

    public static String convertDateToOracleToDateExp(Date date) {
        return convertDateToOracleToDateExp(date, "yyyy-MM-dd HH:mm:ss");
    }

    public static String convertDateToOracleToDateExp(String dateStr) {
        return "TO_DATE('" + dateStr + "','YYYY-MM-DD HH24:MI:SS')";
    }

    public static Date parseDate(String strDate, String formate) {
        DateFormat df = new SimpleDateFormat(formate);
        Date date = null;

        try {
            date = df.parse(strDate);
        } catch (Exception var5) {
            LOGGER.error(String.format("DateUtil.parseDate:%s", var5));
            date = null;
        }

        return date;
    }

    public static int getYearByDate(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(1);
    }

    public static Date addHour(int addHour) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(11, addHour);
        return calendar.getTime();
    }

    public static Date getCurrYearFirst() {
        Calendar currCal = Calendar.getInstance();
        int currentYear = currCal.get(1);
        return getYearFirst(currentYear);
    }

    public static Date getCurrYearLast() {
        Calendar currCal = Calendar.getInstance();
        int currentYear = currCal.get(1);
        return getYearLast(currentYear);
    }

    public static Date getYearFirst(int year) {
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(1, year);
        return calendar.getTime();
    }

    public static Date getYearLast(int year) {
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(1, year);
        calendar.roll(6, -1);
        return calendar.getTime();
    }

    public static int getMaxDayByYearMonth(String dateTime) {
        int days = 0;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        try {
            Date date = sdf.parse(dateTime);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            days = calendar.getActualMaximum(5);
        } catch (ParseException var5) {
            LOGGER.error(String.format("DateUtil.getMaxDayByYearMonth:%s", var5));
        }

        return days;
    }

    public static long getDistanceDays(String startTime, String endTime) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        long days = 0L;

        try {
            Date one = df.parse(startTime);
            Date two = df.parse(endTime);
            long time1 = one.getTime();
            long time2 = two.getTime();
            long diff;
            if (time1 < time2) {
                diff = time2 - time1;
            } else {
                diff = time1 - time2;
            }

            days = diff / 86400000L;
        } catch (Exception var13) {
            LOGGER.error(String.format("DateUtil.getDistanceDays:%s", var13));
        }

        return days;
    }

    public static boolean isInDate(Date date, String strDateBegin, String strDateEnd) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strDate = sdf.format(date);
        int strDateH = Integer.parseInt(strDate.substring(11, 13));
        int strDateM = Integer.parseInt(strDate.substring(14, 16));
        int strDateS = Integer.parseInt(strDate.substring(17, 19));
        int strDateBeginH = Integer.parseInt(strDateBegin.substring(0, 2));
        int strDateBeginM = Integer.parseInt(strDateBegin.substring(3, 5));
        int strDateBeginS = Integer.parseInt(strDateBegin.substring(6, 8));
        int strDateEndH = Integer.parseInt(strDateEnd.substring(0, 2));
        int strDateEndM = Integer.parseInt(strDateEnd.substring(3, 5));
        int strDateEndS = Integer.parseInt(strDateEnd.substring(6, 8));
        if (strDateH >= strDateBeginH && strDateH <= strDateEndH) {
            if (strDateH > strDateBeginH && strDateH < strDateEndH) {
                return true;
            } else if (strDateH == strDateBeginH && strDateM >= strDateBeginM && strDateM <= strDateEndM) {
                return true;
            } else if (strDateH == strDateBeginH && strDateM == strDateBeginM && strDateS >= strDateBeginS && strDateS <= strDateEndS) {
                return true;
            } else if (strDateH == strDateEndH && strDateM <= strDateEndM) {
                return true;
            } else {
                return strDateH == strDateEndH && strDateS <= strDateEndS;
            }
        } else {
            return false;
        }
    }

    public static int getWeekDay() {
        Calendar now = Calendar.getInstance();
        boolean isFirstSunday = now.getFirstDayOfWeek() == 1;
        int weekDay = now.get(7);
        if (isFirstSunday) {
            --weekDay;
            if (weekDay == 0) {
                weekDay = 7;
            }
        }

        return weekDay;
    }

    public static int getWeekDay(Date date) {
        Calendar now = Calendar.getInstance();
        now.setTime(date);
        boolean isFirstSunday = now.getFirstDayOfWeek() == 1;
        int weekDay = now.get(7);
        if (isFirstSunday) {
            --weekDay;
            if (weekDay == 0) {
                weekDay = 7;
            }
        }

        return weekDay;
    }

    public static double getDistanceHours(String startTime, String endTime) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        DecimalFormat dec = new DecimalFormat(twoDecimalFormat);
        String hours = "";

        try {
            Date one = df.parse(startTime);
            Date two = df.parse(endTime);
            long time1 = one.getTime();
            long time2 = two.getTime();
            double diff = (double)Math.abs(time1 - time2);
            hours = dec.format(diff / 3600000.0D);
        } catch (ParseException var13) {
            LOGGER.error(String.format("DateUtil.getDistanceHours:%s", var13));
        }

        return Double.valueOf(hours);
    }

    public static int getDistanceSecond(String startTime, String endTime) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        DecimalFormat dec = new DecimalFormat(twoDecimalFormat);
        String seconds = "";

        try {
            Date one = df.parse(startTime);
            Date two = df.parse(endTime);
            long time1 = one.getTime();
            long time2 = two.getTime();
            double diff = (double)(time1 - time2);
            seconds = dec.format(diff / 1000.0D);
        } catch (ParseException var13) {
            LOGGER.error(String.format("DateUtil.getDistanceSecond:%s", var13));
        }

        return Double.valueOf(seconds).intValue();
    }

    public static int getDistanceSecond(String startTime) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        DecimalFormat dec = new DecimalFormat("##0.0");
        Date two = new Date();
        String hours = "";

        try {
            Date one = df.parse(startTime);
            long time1 = one.getTime();
            long time2 = two.getTime();
            long diff = time1 - time2;
            hours = dec.format(diff / 1000L);
        } catch (ParseException var12) {
            LOGGER.error(String.format("DateUtil.getDistanceSecond:%s", var12));
        }

        return Double.valueOf(hours).intValue();
    }

    public static long getDistanceMin(Date startTime, Date endTime) {
        return (startTime.getTime() - endTime.getTime()) / 60000L;
    }

    public static String getTime(String dateTime, int state) {
        Date date = parseDate(dateTime, "yyyy-MM-dd HH:mm:ss");
        String time = "";
        switch(state) {
            case 0:
                time = convertDateToOracleToDateExp(date, "yyyy年");
                break;
            case 1:
                String season = "";
                int month = Integer.parseInt(getMonth(date));
                if (month < 3) {
                    season = "一";
                } else if (month < 6) {
                    season = "二";
                } else if (month < 10) {
                    season = "三";
                } else {
                    season = "四";
                }

                time = convertDateToOracleToDateExp(date, "yyyy年") + String.format("第%s季度", season);
                break;
            case 2:
                time = convertDateToOracleToDateExp(date, "yyyy年MM月");
        }

        return time;
    }

    static enum DateConstants {
        TODAY(0),
        NEARLYWEEK(1),
        MONTH(2),
        NEARLYMONTH(3),
        LASTWEEK(4);

        private int value;

        private DateConstants(int value) {
            this.value = value;
        }
    }
}
